package com.test.BlockingQueueTest;

import java.util.concurrent.BlockingQueue;

/**
 * Created by yang on 17/3/22.
 */
public class Producer implements Runnable{
    BlockingQueue<String> queue;

    public Producer(BlockingQueue<String> queue){
        this.queue = queue;
    }

    @Override
    // run方法实现将手机号放入阻塞队列中
    public void run() {
        try {
            Basic.getPhone();
            for (int i = 0; i < (Basic.phones.size()); i++) {
                try {
                    queue.put(Basic.phones.get(i));
                    System.out.println(Basic.phones.get(i) + " 已放入队列");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
